<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8"/>
    <script type="text/javascript" src="js/jquery-1.2.6.js"></script>
    <link type="text/css" rel="stylesheet" href="style/style.css"/>
    <script type="text/javascript" src="plugin/artDialog.js?skin=green"></script>
    <script type="text/javascript">
        document.write('<script type="text/javascript" src="js/'+getQueryStr("language")+'.js"><\/script>');
    </script>
    <title></title>
</head>
<body class="gui">

<div id="wrapper">
<div id="content">
<div id="header">
    <div id="logo">
        <h1>Control Panel</h1>
    </div>
</div>
<div id="main">
    <div id="contents_stat">
        <div id="guideCaller">
        <form name="filters" method="post">
            <fieldset>
                <legend>
                    <label sid="extension.call_id"></label>
                </legend>
                <div class="frame_tab_layer">
                    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="cmenutitle">
                        <td colspan="2" align="left" style="padding-right:50px;">
                        </td>
                        </tr>
                        <tr>
                            <td align="center" width="33%">
                                <label sid="extension.call_id"></label>

                            </td>
                            <td class="frame_tab_right">
                                <span style="padding-left:50px;"></span>
                                <input type="radio" name="id454" id="id454_1" value="on" checked/>
                                <label sid="sip_trunk.table3_td4_option1"></label>

                                <span style="padding-left:80px;"></span>
                                <input type="radio" name="id454" id="id454_2" value="off"/>
                                <label sid="sip_trunk.table3_td4_option2"></label>

                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" class="frame_tab_right" style="padding-right:50px;">
                            </td>
                        </tr>
                    </table>
                </div>
            </fieldset>
            <fieldset id="ipextension">
                <legend>
                    <label sid="server.table1_note4"></label>

                </legend>
                <div class="frame_tab_layer">
                    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="cmenutitle" id="IP_Phone">
                        <tr>
                            <td colspan="4" class="frame_tab_right" style="padding-right:50px;">
                            </td>
                        </tr>
                        <tr>
                            <td align="center" width="10%">
                                <label sid="ivr_menu.ip_extension"></label>

                                1
                            </td>
                            <td align="left">
                                <label>
                                    <label sid="fxo_capture.td2"></label>
                                 </label>
                                &nbsp;&nbsp;<input type="text" name="id401_0" id="id401_0" size="7" maxlength="11" value="205"/>
                                <label>
                                    <label sid="ext_reg.table2_td5"></label>
                                   </label>
                                &nbsp;&nbsp;<input type="text" name="id591_0" id="id591_0" size="7" maxlength="11"/>
                            </td>
                            <td align="center" width="10%">
                                <label sid="ivr_menu.ip_extension"></label>

                                2
                            </td>
                            <td align="left">
                                <label>
                                    <label sid="fxo_capture.td2"></label>
                                 </label>
                                &nbsp;&nbsp;<input type="text" name="id401_1" id="id401_1" size="7" maxlength="11"
                                                   value="206"/>
                                <label>
                                    <label sid="ext_reg.table2_td5"></label>
                                  </label>
                                &nbsp;&nbsp;<input type="text" name="id591_1" id="id591_1" size="7" maxlength="11"/>
                            </td>
                        </tr>
                        <tr>
                            <td align="center" width="10%">
                                <label sid="ivr_menu.ip_extension"></label>

                                3
                            </td>
                            <td align="left">
                                <label>
                                    <label sid="fxo_capture.td2"></label>
                                   </label>
                                &nbsp;&nbsp;<input type="text" name="id401_2" id="id401_2" size="7" maxlength="11"
                                                   value="207"/>
                                <label>
                                    <label sid="ext_reg.table2_td5"></label>
                                    </label>
                                &nbsp;&nbsp;<input type="text" name="id591_2" id="id591_2" size="7" maxlength="11"/>
                            </td>
                            <td align="center" width="10%">
                                <label sid="ivr_menu.ip_extension"></label>
                                4
                            </td>
                            <td align="left">
                                <label>
                                    <label sid="fxo_capture.td2"></label>
                                </label>

                                &nbsp;&nbsp;<input type="text" name="id401_3" id="id401_3" size="7" maxlength="11"
                                                   value="208"/>
                                <label>
                                    <label sid="ext_reg.table2_td5"></label>
                                   </label>
                                &nbsp;&nbsp;<input type="text" name="id591_3" id="id591_3" size="7" maxlength="11"/>
                            </td>
                        </tr>
                        <tr>
                            <td align="center" width="10%">
                                <label sid="ivr_menu.ip_extension"></label>

                                5
                            </td>
                            <td align="left">
                                <label>
                                    <label sid="fxo_capture.td2"></label>
                                 </label>

                                &nbsp;&nbsp;<input type="text" name="id401_4" id="id401_4" size="7" maxlength="11"
                                                   value="209"/>
                                <label>
                                    <label sid="ext_reg.table2_td5"></label>
                                  </label>
                                &nbsp;&nbsp;<input type="text" name="id591_4" id="id591_4" size="7" maxlength="11"/>
                            </td>
                            <td align="center" width="10%">
                                <label sid="ivr_menu.ip_extension"></label>

                                6
                            </td>
                            <td align="left">
                                <label>
                                    <label sid="fxo_capture.td2"></label>
                                  </label>

                                &nbsp;&nbsp;<input type="text" name="id401_5" id="id401_5" size="7" maxlength="11"
                                                   value="210"/>
                                <label>
                                    <label sid="ext_reg.table2_td5"></label>
                                </label>
                                &nbsp;&nbsp;<input type="text" name="id591_5" id="id591_5" size="7" maxlength="11"/>
                            </td>
                        </tr>
                        <tr>
                            <td align="center" width="10%">
                                <label sid="ivr_menu.ip_extension"></label>

                                7
                            </td>
                            <td align="left">
                                <label>
                                    <label sid="fxo_capture.td2"></label>
                                  </label>
                                &nbsp;&nbsp;<input type="text" name="id401_6" id="id401_6" size="7" maxlength="11"
                                                   value="211"/>
                                <label>
                                    <label sid="ext_reg.table2_td5"></label>
                                 </label>
                                &nbsp;&nbsp;<input type="text" name="id591_6" id="id591_6" size="7" maxlength="11"/>
                            </td>
                            <td align="center" width="10%">
                                <label sid="ivr_menu.ip_extension"></label>

                                8
                            </td>
                            <td align="left">
                                <label>
                                    <label sid="fxo_capture.td2"></label>
                                </label>

                                &nbsp;&nbsp;<input type="text" name="id401_7" id="id401_7" size="7" maxlength="11"
                                                   value="212"/>
                                <label>
                                    <label sid="ext_reg.table2_td5"></label>
                                  </label>
                                &nbsp;&nbsp;<input type="text" name="id591_7" id="id591_7" size="7" maxlength="11"/>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="4" align="left" style="padding-right:50px;">
                            </td>
                        </tr>
                    </table>
                </div>
            </fieldset>
            <br/>

            <div class="submitFooter">
                <input class="button" type="button"  sid="guide.previous" name="previous" value="" />
                <input class="button" type="button"  sid="guide.next" name="submit" value="" />
                <input class="button" type="button"  sid="main.cancel" name="cancel" value="" />
            </div>
        </form>
        </div>
        <div id="guideover" style="display: none;">
            <form name="filters" method="post">
                <fieldset>
                    <legend>
                        <label sid="guide.over2"></label>
                    </legend>
                    <div class="frame_tab_layer">
                        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="cmenutitle">
                            <tr>
                                <td class="frame_tab_right">
                                    <img src="images/tick.png"/>
                                    <label sid="msg.guideSuccess1"></label>
                                    <label sid="msg.guideSuccess5"></label>

                                    <a href="index.htm">
                                        <label sid="msg.guideSuccess6"></label>
                                    </a>
                                    <label sid="msg.guideSuccess5_2"></label>

                                </td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                            </tr>
                            <tr>
                                <td colspan="2" class="frame_tab_right">
                                    <span style="padding-left: 50px;"></span>
                                    <label sid="msg.guideSuccess2_part"></label>

                                </td>
                            </tr>
                            <tr>
                                <td colspan="2" class="frame_tab_right">
                                    <span style="padding-left: 50px;"></span>
                                    <label sid="msg.guideSuccess2"></label>

                                </td>
                            </tr>
                            <tr>
                                <td colspan="2" class="frame_tab_right">
                                    <span style="padding-left: 50px;"></span>
                                    <label sid="msg.guideSuccess3"></label>

                                </td>
                            </tr>
                            <tr>
                                <td colspan="2" class="frame_tab_right">
                                    <span style="padding-left: 50px;"></span>
                                    <label sid="msg.guideSuccess4"></label>

                                </td>
                            </tr>
                            <tr>
                                <td colspan="2" class="frame_tab_right">
                                </td>
                            </tr>
                        </table>
                    </div>
                </fieldset>
            </form>
        </div>
    </div>
</div>

<div id="floatKiller"></div>
<div id="statusInfo">

    <div class="info"><span id="loginuser"></span></div>
    <!--<div class="info"><script type="text/javascript">Capture(share.logintime)</script><span id="uptime"></span></div>-->
    <div class="info">
        <button class="logout" onclick="reboot();"><img src="images/reboot.gif" border="0">&#160;
            <label sid="tools.td10"></label>
        </button>
        <button class="logout" onclick="logout();"><img src="images/logout.gif" border="0">&#160;
            <label sid="share.logout"></label>
        </button>
    </div>
</div>

</div>
</div>
<div id="lock_div">&nbsp; </div>
<div id="lock_div2">&nbsp;</div>
<div id="message_panel"><span id="mess">&nbsp;</span><br/>
    <br/>
    <img src="images/jd.gif"/>
</div>
<div id="rightMenu" style="display: none">
    <ul>
        <li id="editWords">Edit</li>
        <li id="defaultValue">Default</li>
    </ul>
</div>
<script type="text/javascript" src="lib.js"></script>
<script type="text/javascript" src="js/message_panel.js"></script>
<script type="text/javascript">
/*var sendtext = "&id=2024";
 DataRequest("get_json",sendtext,function(data){
 updatecfgvalue("id2024",data["id2024"]);
 });
 */

$("label").each(function () {
    var currentVal =$(this);
    var values =eval($(this).attr("sid"));
    if(typeof(values)!=="undefined"){

     $(this).html(decodeURIComponent(values));

    $(this).rightClick(function(){
        if(currentVal.attr("sid")) {
            showEditDialog(currentVal);
            currentVal.addClass("EditPosition");
        }
    });
    }
    if($(this).html()=="" && $(this).parent().hasClass("definition")){
        $(this).parent().hide();
        $(this).parent().prev().hide();
    }
});

$("input[type='button']").each(function () {
    $(this).val(eval($(this).attr("sid")));
    var currentButton =$(this);
    $(this).rightClick(function(){
        showEditDialog(currentButton,'val');
        currentButton.addClass("EditPosition");
    })


});

$("button").each(function(){
    var currentButton =$(this);
    var ButtonVal = currentButton.find("label");
    $(this).rightClick(function(){
        if(ButtonVal.attr("sid")) {
            showEditDialog(ButtonVal);
            ButtonVal.addClass("EditPosition");
        }
    })
});

var thisurl = document.URL;
var HomeCookie = getCookie("HomePhone");
var oldsettext = thisurl.split("?")[1];
oldsettext = oldsettext.substr(8, oldsettext.length);
var setarray = oldsettext.split("&");
var types = "";
var settext = "";


for (var i = 0; i < setarray.length; i++) {
    if (setarray[i].indexOf("types=") >= 0) {
        types = setarray[i].split("=")[1];
    } else {
        settext += "&" + setarray[i];
    }
}
if (types == "home") {
    $("#IP_Phone").find("tr:gt(1)").hide();
    if(HomeCookie == null){
    $("#id401_0").val(7);
    $("#id401_1").val(8);
        for(var j =0;j<8;j++){
            $("#id591_"+j).val(Fill());
        }
    }else{
     var arr=HomeCookie.split(",");
        $("#id401_0").val(arr[0].split("*")[0]);
        $("#id591_0").val(arr[0].split("*")[1]);
        $("#id401_1").val(arr[1].split("*")[0]);
        $("#id591_1").val(arr[1].split("*")[1]);
    }
    $("[name=submit]").attr("value", guide.next);
} else {

        for(var j =0;j<8;j++){
            $("#id591_"+j).val(Fill());
        }

    $("#IP_Phone").find("tr:gt(1)").show();
    $("[name=submit]").attr("value", guide.over);
}


var ipline1 = "";
var ipline2 = "";
var trunk = "";
var line1 = "";
var line2 = "";
var linearray = new Array();
var i = 0;
var j = 0;
xmlDataRequest("get_data", "&id=4000&id=4001&id=4020", function (data) {
    $(data).find("item").each(function () {
        if ($(this).attr("id") == "4000") {
            $(this).find("value").each(function () {
                if ($(this).text().split("/")[0] == "FXS-1") {
                    line1 = $(this).text().split("/")[1];
                } else if ($(this).text().split("/")[0] == "FXS-2") {
                    line2 = $(this).text().split("/")[1];
                }
            });
            if (types == "home") {
                if (line2 !== "") {
                    settext += "&id751=on&id759=on&line_id=1&id750=&line_id=2&id750=00/IP&line_id=3&id750=&line_id=4&id750=";
                    settext += "&line_id=" + line1 + "&id401=5&line_id=" + line2 + "&id401=6";
                } else {
                    settext += "&id751=on&id759=on&line_id=1&id750=&line_id=2&id750=00/FXO&line_id=3&id750=&line_id=4&id750=";
                    settext += "&line_id=" + line1 + "&id401=6";
                }
            } else {
                if (line2 !== "") {
                    settext += "&id751=off&id759=off&line_id=1&id750=0/OPER&line_id=2&id750=9/LIP&line_id=3&id750=7/IP&line_id=4&id750=";
                    settext += "&line_id=" + line1 + "&id401=200&line_id=" + line2 + "&id401=201";
                } else {
                    settext += "&id751=off&id759=off&line_id=1&id750=0/OPER&line_id=2&id750=9/LIP&line_id=3&id750=7/FXO&line_id=4&id750=6/IP";
                    settext += "&line_id=" + line1 + "&id401=200";
                }
            }

        } else if ($(this).attr("id") == "4001") {
            $(this).find("value").each(function () {
                if ($(this).text().split("/")[0] == "FXO-2") {
                    trunk = $(this).text().split("/")[1];
                }
            });
            if (trunk !== "") {
                if (types == "home") {
                    if (line2 !== "") {
                        settext += "&line_id=" + trunk + "&id437=on&id447=off&id469=5";
                    } else {
                        settext += "&line_id=" + trunk + "&id437=on&id447=off&id469=6";
                    }
                } else {
                    settext += "&line_id=" + trunk + "&id437=off&id447=off&id469=";
                }
            }
        } else if ($(this).attr("id") == "4020") {
            $(this).find("value").each(function () {
                linearray[i] = $(this).text().split("/")[1];
                i++;
            });
        }
    });
});


$("#id454_1").attr("checked", true);

$("[name=submit]").click(function () {
    var phoneNum ='',passWord='';
    for(var j =0;j<8;j++){

        phoneNum = $("#id401_"+j).val();
        passWord = $("#id591_"+j).val();

        if(phoneNum==passWord){
            alert(errmsg.err103);
            $("#id591_"+j).focus();
                return false;
        }
    }
    $(".errormsg").html('');
    if ($("#id454_1").attr("checked")) {
        if (trunk !== "") {
            settext += "&line_id=" + trunk + "&id454=on";
        }
    } else {
        if (trunk !== "") {
            settext += "&line_id=" + trunk + "&id454=off";
        }
    }
    if (types == "home") {
        for (var s = 0; s < linearray.length; s++) {
            if (s == 0) {
                settext += "&line_id=" + linearray[s] + "&id401=" + $("#id401_" + s).val() + "&id591=" + $("#id591_" + s).val();
            } else if (s == 1) {
                settext += "&line_id=" + linearray[s] + "&id401=" + $("#id401_" + s).val() + "&id591=" + $("#id591_" + s).val();
            } else {
                settext += "&line_id=" + linearray[s] + "&id401=&id591=";
            }
        }
    } else {
        for (var s = 0; s < linearray.length; s++) {
            settext += "&line_id=" + linearray[s] + "&id401=" + $("#id401_" + s).val() + "&id591=" + $("#id591_" + s).val();
        }
    }

    settext = settext.replace(/\#/g, "%23");

    if (types == "company") {
        settext += "&id2010=1";
        var cannotModify = msg.cannotModify1;
        var noPower = msg.cannotModify2;
        var reboot = msg.submitSuccess;
        var cannotDelete = msg.cannotDelete;
        var cfgError = msg.cfgError;
        //  show_message("pro", msg.saving);
        $.ajax({
            type:"POST", url:modules["set_data"], data:settext + "&tmp = " + Math.random(), timeout:1000, dataType:"xml", error:function (XMLHttpRequest, textStatus, errorThrown) {
                $("#guideCaller").slideUp();
                $("#guideover").slideDown();

            }, success:function (xml) {
                $(xml).find('rsp').each(function () {
                    $("#message_panel").fadeOut();
                    $("#lock_div").hide();
                    $("#lock_div2").hide();
                    $("#message_panel").hide();
                    var stat = $(this).attr('stat');
                    if (stat == "ok") {
                        //show_message("success",success);
                        alert(reboot);
                        $("#guideCaller").slideUp();
                        $("#guideover").slideDown();

                    } else if (stat == "restart" || stat == "reboot") {
                        //show_message("success",reboot);
                        alert(reboot);

                        $("#guideCaller").slideUp();
                        $("#guideover").slideDown();

                    } else if (stat == "fail") {
                        //show_message("err",msg.cfgError);
                        alert(msg.cfgError);
                        $(xml).find('Error').each(function () {
                            var code = $(this).attr('code');
                            if (code == 4) {
                                //show_message("err",cannotModify);
                                alert(cannotModify);
                            } else if (code == 5) {
                                gotologin();
                            } else {
                                if ($("[name = group]").attr("name")) {
                                    var str = '';
                                    $(xml).find('Error').each(function () {
                                        var code = $(this).attr('code');
                                        if (code == 4) {
                                            //show_message("err",cannotModify);
                                            alert(cannotModify);
                                        } else if (code == 5) {
                                            gotologin();
                                        } else {
                                            var strArray = $(this).attr('msg').split(" ");
                                            var mid = strArray[1].substr(2);
                                            str += mid + ",";
                                        }
                                    });
                                    //show_message("err",cannotDelete);
                                    alert(cannotDelete);
                                } else if ($("[name = tra-dis]").attr("name")) {
                                    //show_message("err",dialingRules.help5);
                                    alert(dialingRules.help5);
                                } else {
                                    var strArray = $(this).attr('msg').split(" ");
                                    var mid = strArray[1].substr(2);
                                    if (mid == 32 || mid == 31 || mid == 33 || mid == 34) {
                                        //show_message("err",cfgError);
                                        alert(cfgError);
                                    } else if ($(this).attr('msg').indexOf("line_id") >= 0) {
                                        var str1 = $(this).attr('msg').split(",");
                                        var str2 = str1[1].split(" ");
                                        var line_id = str2[1].split("=")[1];
                                        $("#msg" + mid + "_" + line_id).html('<img src="images/check_error.gif">');
                                    } else {
                                        showerror(mid);
                                    }
                                }
                            }
                        });
                    }
                });
            }
        });

        return true;
    } else {

        setCookie("HomePhone",$("#id401_0").val()+"*"+$("#id591_0").val()+","+$("#id401_1").val()+"*"+$("#id591_1").val());
        window.location.href = "homepage.htm?settext=" + settext;
    }
});
$("[name=previous]").click(function () {
    history.back();
});

$("[name=cancel]").click(function () {
    window.location.href="menuGuide.htm?language="+getQueryStr("language");
});
function Fill(){
    var rndnumb='';
    for (i=1;i<=6;i++){
        n = Math.floor(Math.random()*10);
        rndnumb= rndnumb + n;
    }
    return rndnumb;
}

</script>
</body>
</html>
